package hit.reports;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Abstract class used to build a report.
 *
 */
public abstract class ReportBuilder {
	
	public static final String PATH = "reports/";
	public static final String DATE_FORMAT = "MM/dd/yyyy";
	
	/**
	 * The title of the report.
	 */
	private String title;
	
	/**
	 * The printable objects within the report.
	 */
	protected List<BuilderObject> objects;
	
	/**
	 * Default constructor
	 */
	public ReportBuilder()
	{
		title = "";
		objects = new ArrayList<BuilderObject>();
	}
	
	/**
	 * Gets the value of the report's title.
	 * @return the value of title.
	 */
	public String getTitle()
	{
		return title;
	}

	/**
	 * Set the value of the report's title.
	 * @param title The new value of the title.
	 * @throws IllegalArgumentException if the title is null
	 */
	public void setTitle(String title) throws IllegalArgumentException
	{
		if (title == null)
		{
			throw new IllegalArgumentException();
		}
		
		this.title = title;
	}

	/**
	 * Adds a new {@link BuilderObject} to the report.
	 * @param object The BuilderObject to be added.
	 * @throws IllegalArgumentException if the object is null or already in the system.
	 */
	public void AddObject(BuilderObject object) throws IllegalArgumentException
	{
		if (object == null || objects.contains(object))
			throw new IllegalArgumentException();
		
		objects.add(object);
	}
	
	/**
	 * Removes a {@link BuilderObject} from the report.
	 * @param object The BuilderObject to be removed.
	 * @throws IllegalArgumentException if the object is null 
	 */
	public void RemoveObject(BuilderObject object) throws IllegalArgumentException
	{
		if (object == null)
			throw new IllegalArgumentException();
		
		objects.remove(object);
	}
	
	/**
	 * Gets the iterator for all the objects in the report.
	 * @return The iterator
	 */
	public Iterator<BuilderObject> GetObjectsIterator()
	{
		return objects.iterator();
	}
	
	/**
	 * Clears all objects currently in the builder.
	 */
	public void Clear()
	{
		this.title = "";
		this.objects.clear();
	}
}
